//
//  MyOrderBaseViewController.m
//  customer
//
//  Created by Holothurian on 2018/10/19.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "MyOrderBaseViewController.h"
#import "JXCategoryTitleView.h"
#import "MyOrderListViewController.h"
#import "MyOrderSearchViewController.h"

@interface MyOrderBaseViewController (){
    BOOL _isActive;
}

@property (nonatomic, strong) JXCategoryTitleView *myCategoryView;

@end

@implementation MyOrderBaseViewController

- (void)viewDidLoad {
    if (!self.titles) {
        _titles = @[@"全部订单", @"待指派", @"待上门", @"待确认", @"待付款", @"已完成",@"取消订单"];
    }
    [super viewDidLoad];
    
    [self createTitleItem];
    
    [self createSearchBar];
}

- (void)createTitleItem{
    self.title = @"我的订单";
    
    self.myCategoryView.titles = self.titles;
    //与cell等宽
    self.isNeedIndicatorPositionChangeItem = YES;
    self.myCategoryView.titleColorGradientEnabled = YES;
    self.myCategoryView.titleColor = [HSPublic colorWithHexString:@"666666"];
    self.myCategoryView.titleSelectedColor = [HSPublic colorWithHexString:@"1F89FF"];
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineWidth = JXCategoryViewAutomaticDimension;
    lineView.indicatorLineViewColor = [HSPublic colorWithHexString:@"1F89FF"];
    self.myCategoryView.indicators = @[lineView];
}

- (void)createSearchBar{
    UIView * addBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    UIImageView * addImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
    addImageView.image = [UIImage imageNamed:@"searchBarImg"];
    addImageView.userInteractionEnabled = YES;
    [addBgView addSubview:addImageView];
    UITapGestureRecognizer * backTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(searchTapClick)];
    [addBgView addGestureRecognizer:backTap];
    UIBarButtonItem * rightBtnItem = [[UIBarButtonItem alloc]initWithCustomView:addBgView];
    self.navigationItem.rightBarButtonItem = rightBtnItem;
}

- (void)searchTapClick{
    MyOrderSearchViewController *searchVC = [[MyOrderSearchViewController alloc]init];
    TAB_PUSH(self, searchVC, YES);
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receiveRepairOrderPost:) name:kPostNotificationForRepairOrder object:nil];
    if (self.isPop) {
        NSString *viewString = self.popArray.firstObject;
        if (!k_Is_Empty(viewString)) {
            NSInteger viewTag = [viewString integerValue];
            MyOrderListViewController *listVC = self.childViewControllers[viewTag];
            [self.categoryView selectItemAtIndex:viewTag];
            if (listVC.listBlock) {
                listVC.listBlock(viewTag);
            }
        }
    }
}

- (void)receiveRepairOrderPost:(NSNotification *)notify{
    NSInteger index = [[notify.object objectForKey:@"postIndex"] integerValue];
    MyOrderListViewController *listVC = self.childViewControllers[index];
    [self.categoryView selectItemAtIndex:index];
    if (listVC.listBlock) {
        listVC.listBlock(index);
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:kPostNotificationForRepairOrder object:nil];
}

- (JXCategoryTitleView *)myCategoryView {
    return (JXCategoryTitleView *)self.categoryView;
}

- (NSUInteger)preferredListViewCount {
    return self.titles.count;
}

- (Class)preferredCategoryViewClass {
    return [JXCategoryTitleView class];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
